﻿using System.Collections.Generic;
using System.Linq;
using PersonaLibrary.PersonaliiReference;

namespace PersonaLibrary.ViewModel.EmployeeViewModel
{
    internal class EmployeeViewModel : ReferenceEditableItem<Employee>
    {
        public EmployeeViewModel()
        {
            EditableItem = new Employee();
            SexSource = Context.CreateAndExecuteQuery<Sex>("Sex").ToList();
        }

        public EmployeeViewModel(int id)
        {
        	EditableItem =
        		Context.CreateAndExecuteQuery<Employee>(
					string.Format("Employee?$filter=Id eq {0}&$expand=EmployeeNoteLink,ConnectionJobEmplDep/Department,ConnectionJobEmplDep/Job,ConnectionJobEmplDep/Department/Organization", id)).Single();
			SexSource = SexSource = Context.CreateAndExecuteQuery<Sex>("Sex").ToList();
         }

        #region Pupblic Properties

        public List<Sex> SexSource { private set; get; }
        
        #endregion
        
        #region Parent override
		
        public override bool CanCommit()
        {
            if (string.IsNullOrEmpty(EditableItem.Surname)) 
				return false;            
            return true;
        }

        #endregion
    }
}
